<template>
  <div class="search-area">
    <!-- 1. 搜索区域 -->
    <el-form ref="formRef" :model="form" label-width="auto" size="large">
      <el-row>
        <el-col :span="8">
          <el-form-item label="用户名" prop="name">
            <el-input v-model="form.name" placeholder="请输入您的用户名" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="真实姓名" prop="realName">
            <el-input v-model="form.realName" placeholder="请输入您的真实姓名" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="电话号码" prop="phone">
            <el-input v-model="form.phone" placeholder="请输入您的电话号码" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="8">
          <el-form-item label="状态" prop="state">
            <el-select v-model="form.state" placeholder="选择查询的状态">
              <el-option label="启用" :value="1" />
              <el-option label="禁用" :value="0" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="创建时间" prop="createAt">
            <el-date-picker v-model="form.createAt" type="daterange" range-separator="-" start-placeholder="开始时间"
              end-placeholder="结束时间" />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    <!-- 2. 按钮区域 -->
    <div class="btns">
      <el-button @click="resetClick" icon="refresh">重置</el-button>
      <el-button type="primary" icon="search" @click="onSearchClick">查询</el-button>
    </div>
  </div>
</template>

<script setup lang="ts">
import type { FormInstance } from 'element-plus';
import { reactive, ref } from 'vue';

const emit = defineEmits(['searchClick', 'resetClick'])

const formRef = ref<FormInstance>();

const form = reactive({
  name: '',
  state: undefined,
  realName: '',
  phone: '',
  createAt: '',
})

function resetClick() {
  formRef.value?.resetFields();

  emit('resetClick')
}

function onSearchClick() {
  formRef.value?.validate(valid => {
    if (valid) {
      emit('searchClick', form)
    }
  })
}
</script>
<style scoped lang="less">
.search-area {
  background-color: white;
  padding: 20px;
}

.el-form-item {
  padding: 20px 30px;
  margin-bottom: 0px;
}

.btns {
  padding: 0 30px 20px 0;
  text-align: right;

}
</style>
